package cn.com.headfree.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.RoutesRefreshedEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.com.headfree.locator.CustomRouteLocator;

@CrossOrigin("*")
@RestController
@RequestMapping(value = "/zuul", produces = "application/json;charset=UTF-8")
public class RefreshRouteController {
	@Autowired
    private ApplicationEventPublisher publisher;

    @Autowired
    private CustomRouteLocator routeLocator;

    @RequestMapping("/refresh")
    public void refreshRoute() {
        RoutesRefreshedEvent routesRefreshedEvent = new RoutesRefreshedEvent(routeLocator);
        publisher.publishEvent(routesRefreshedEvent);
    }
}
